package org.nowcoder.huawei.c100;

import java.util.Arrays;

/**
 * 38 ：字符串变换最小字符串
 */
public class HC038 {
    public static void main(String[] args) {
       solve("bcdefa");
    }

    public static void solve(String s) {
        char[] var = s.toCharArray();
        Arrays.sort(var);
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (var[i] != c) { //var[i] 现在就是最小的字符
                int index = i + 1;
                for (; index < s.length(); index++) {
                    if (s.charAt(index) == var[i]) {
                        break;
                    }
                }
                sb.setCharAt(index,c);
                sb.setCharAt(i,s.charAt(index));
                break;
            }
        }
        System.out.println(sb);
    }
}
